#include "MapManager.h"
#include "Map.h"

#include <fstream>
#include "BaseObject.h"
#include "../TinyXML/tinyxml.h"
#include "GameplayState.h"
#include "Game.h"
#include "Player.h"
#include "Guard.h"
#include "Officer.h"
#include "Worker.h"
#include "Turret.h"
#include "SecurityCamera.h"
#include "SpawnDoor.h"
#include "PickUp.h"
#include "EnvironmentalObject.h"
#include "Computer.h"
#include "KeyPad.h"
#include "AlarmButton.h"
#include "Door.h"
#include "Shadow.h"

#include "EntityManager.h"
//#include "../resource/config/"


enum EntityBucket {  BUCKET_ENEMIES, BUCKET_PLAYER, BUCKET_ENVIRO, BUCKET_BULLETS, BUCKET_SHADOWS, BUCKET_NONCOLLIDABLE };



/*static*/ MapManager * MapManager::GetInstance()
{
	static MapManager sInstance;

	return &sInstance;
}

BaseObject* MapManager::LoadLevel(GamerProfile& currProfile, EntityManager* m_pEntities, vector<SGD::Rectangle*>& FOVCollidables, Graph<SGD::Point*>& navGraph)
{
	//EntityManager* m_pEntities = new EntityManager;
	
	

	Player* player;
	
	SGD::GraphicsManager * pGraphics = SGD::GraphicsManager::GetInstance();

	TiXmlDocument doc;

	int mapWidth;
	int mapHeight;
	int tileWidth;
	int tileHeight;
	int posX;
	int posY;
	int rectPosX;
	int rectPosY;
	SGD::Point rPos;
	SGD::Point tPos;
	int tileid = -1;
	SGD::HTexture tSetBG;
	std::string filePath;

	int homeNode, alarmNode;

	SGD::Point m_ptCheckPtStart;

	if (doc.LoadFile(levels[currProfile.LevelsComplete].c_str()) == false)
	{
		return nullptr;
	}

	TiXmlElement * root = doc.RootElement();
	if (root == nullptr)
	{
		return nullptr;
	}

	TiXmlElement * level = root->FirstChildElement("world_info");

	level->Attribute("width", &tileWidth);
	level->Attribute("height", &tileHeight);
	level->Attribute("worldWidth", &mapWidth);
	level->Attribute("worldHeight", &mapHeight);

	tStruct.tileSize.width = (float)tileWidth;
	tStruct.tileSize.height = (float)tileHeight;
	tStruct.map.SetMapWidth(mapWidth);
	tStruct.map.SetMapHeight(mapHeight);
	const int cMapWidth = tStruct.map.GetMapWidth();
	const int cMaHeight = tStruct.map.GetMapHeight();


	tStruct.layers.m_vTiles = new Tile*[cMaHeight];

	for (int i = 0; i < cMaHeight; i++)
		tStruct.layers.m_vTiles[i] = new Tile[cMapWidth];

		
	
	

	const char * fpText = level->GetText();
	if (fpText != nullptr)
	{
		string fullPath = fpText;
		int startIndex = fullPath.find_last_of('\\');

		filePath += fullPath.substr(startIndex+1,fullPath.length() );
		string path = "resource/graphics/";
		path += filePath;
		tStruct.map.SetTilePath(path);
	}
	
	TiXmlElement * playerInfo = root->FirstChildElement("player_info");

	

	playerInfo->Attribute("id", &tileid);

	playerInfo->Attribute("posX", &posX);
	playerInfo->Attribute("posY", &posY);
	
	player = CreatePlayer(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities);
	player->SetGamerProfile(currProfile);
	//level = level->NextSiblingElement("tile_info");
	TiXmlElement * tileList = root->FirstChildElement("tile_list");
	TiXmlElement * tileinfo = tileList->FirstChildElement("tile_info");
	
	while (tileinfo != nullptr)
		{
			

		tileinfo->Attribute("rposx", &rectPosX);
		tileinfo->Attribute("rposy", &rectPosY);
		tileinfo->Attribute("posX", &posX);
		tileinfo->Attribute("posY", &posY);
		
		Tile temp;
		

		temp.worldPos.x = (float)posX;
		temp.worldPos.y = (float)posY;

			temp.renderPos.x = (float)rectPosX;
			temp.renderPos.y = (float)rectPosY;
		/*	
			tStruct.pTiles.SetTilePos({ tPos.x, tPos.y });
			tStruct.layers.AddRectPos(rPos);
			tStruct.layers.AddTilePos({ tPos.x, tPos.y});
			tStruct.layers.AddTiles(tStruct.pTiles);
			tStruct.pTiles.SetCollisionRect(tPos.x, tPos.y, tPos.x + tileWidth, tPos.y + tileHeight);
			tStruct.pTiles.AddCollisionRect(tStruct.pTiles.GetCollisionRect());*/

			
			tStruct.layers.m_vTiles[posY / tileHeight][posX / tileWidth] = temp;
			tileinfo = tileinfo->NextSiblingElement("tile_info");
		}

	
	
	TiXmlElement * collisionList = root->FirstChildElement("collsion_list");
	TiXmlElement * collisionInfo = collisionList->FirstChildElement("collision_tile");


	while (collisionInfo != nullptr)
	{
		
		collisionInfo->Attribute("posX", &posX);
		collisionInfo->Attribute("posY", &posY);
		collisionInfo->Attribute("type", &tileid);

		string Event1;
	
		const char * NameandEvents = collisionInfo->GetText();
		if (NameandEvents != nullptr)
		{
			
			std::string events = NameandEvents;
			size_t startIndex = events.find_first_of((char)'//');
			std::string tileEvents = events.substr(0, startIndex);
			Event1 = tileEvents;
			if (Event1 == "CHECKPOINT")
				m_ptCheckPtStart = { (float)posX * tileWidth, (float)posY * tileHeight };

				
		}
		

		if (tileid == 0)
			CreateEnvironment(BaseObject::OBJ_WALL, { (float)posX * tileWidth, (float)posY * tileHeight },  FOVCollidables, m_pEntities, Event1.c_str());

		else
			CreateEnvironment(BaseObject::OBJ_TRIGGER, { (float)posX * tileWidth, (float)posY * tileHeight },  FOVCollidables, m_pEntities, Event1.c_str());

		collisionInfo = collisionInfo->NextSiblingElement("collision_tile");



	}
	TiXmlElement * graphList = root->FirstChildElement("graph_list");
	TiXmlElement * nodeInfo = graphList->FirstChildElement("node_info");
	while (nodeInfo != nullptr)
	{
		int numEdges = 0;
		int edge;

		std::string edgeNode;
		
		nodeInfo->Attribute("posX", &posX);
		nodeInfo->Attribute("posY", &posY);
		nodeInfo->Attribute("index", &tileid);
		nodeInfo->Attribute("numEdges", &numEdges);
		const char* tagCheck = nodeInfo->GetText();
		if (tagCheck != nullptr)
		{
			string tag = tagCheck;
			if (tag == "alarm")
				alarmNode = tileid;
			if (tag == "home")
				homeNode = tileid;
		}
		

		
		SGD::Point* temp = new SGD::Point((float)posX * tileWidth + (tileWidth *0.5f), (float)posY * tileHeight + (tileHeight *0.5f));
		navGraph.addVertex(temp);

		for (int currEdge = 0; currEdge < numEdges; currEdge++)
		{
			edgeNode = "edge";
			edgeNode += std::to_string(currEdge);
			nodeInfo->Attribute(edgeNode.c_str(), &edge);
			if (navGraph.size() == 0)
				break;
			else 
				navGraph[navGraph.size() - 1].addEdge(edge);

		}
	
		
		nodeInfo = nodeInfo->NextSiblingElement("node_info");



	}

	TiXmlElement * objectList = root->FirstChildElement("objects_list");
	TiXmlElement * objectInfo = objectList->FirstChildElement("object_info");
	while (objectInfo != nullptr)
	{
		std::vector<int> waypoints;
		std::string Event1;
		std::string Event2;
		const char* NameandEvents;
		int numwayPoints = 0;
		int numEnemies = 0;
		int startState = 0;

		objectInfo->Attribute("id", &tileid);
		objectInfo->Attribute("numEnemies", &numEnemies);
		objectInfo->Attribute("startState", &startState);
		objectInfo->Attribute("posX", &posX);
		objectInfo->Attribute("posY", &posY);
		objectInfo->Attribute("numWaypoints", &numwayPoints);

		NameandEvents = objectInfo->GetText();
		
		for (int i = 0; i < numwayPoints; i++)
		{
			int index = 0;
			std::string waypoint = "waypoint";
			waypoint += std::to_string(i);
			objectInfo->Attribute(waypoint.c_str(), &index);

			waypoints.push_back(index);

		}

		//Depending on the object type, Take in events made
		switch (tileid)
		{
		case BaseObject::OBJ_CAMERA:
		case BaseObject::OBJ_TURRET:
		case BaseObject::OBJ_THERMAL_CAM:
		case BaseObject::OBJ_ALARM_BUTTON:
		case BaseObject::OBJ_TRIP_LASER:
			
			{
				std::string events = NameandEvents;
				size_t startIndex = events.find_first_of((char)'//');
				std::string tileEvents = events.substr(startIndex + 1, events.length());
				Event1 = tileEvents;
			}
			break;
		case BaseObject::OBJ_DOOR:
		case BaseObject::OBJ_KEYPAD:
		case BaseObject::OBJ_COMPUTER:
		{
			 std::string events = NameandEvents;
			 size_t startIndex = events.find_first_of((char)'//');
			 std::string tileEvents = events.substr(startIndex + 1, events.length());
			 startIndex = tileEvents.find_first_of((char)'//');
			 Event1 = tileEvents.substr(0, startIndex);
			 Event2 = tileEvents.substr(startIndex + 1, tileEvents.length());
		}
			
			break;

		};
		

		switch (tileid)
		{
		case BaseObject::OBJ_CAMERA:
		case BaseObject::OBJ_TURRET:
		case BaseObject::OBJ_THERMAL_CAM:
		case BaseObject::OBJ_GUARD:
		case BaseObject::OBJ_WORKER:
		case BaseObject::OBJ_OFFICER:
			CreateEnemy(tileid, homeNode, alarmNode, startState, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities, player, navGraph, FOVCollidables, waypoints, Event1.c_str());
			/*case BaseObject::OBJ_FILECAB:
			case BaseObject::OBJ_CHAIR:*/
			break;
		case BaseObject::OBJ_ALARM_BUTTON:
			CreateAlarmButton(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities, Event1.c_str());

			break;

		case BaseObject::OBJ_KEYPAD:
			CreateKeyPad(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities, Event1.c_str(), Event2.c_str());
			break;
		case BaseObject::OBJ_DOOR:
			CreateDoor(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities, Event1.c_str());

			break;
		case BaseObject::OBJ_INTEL:
		case BaseObject::OBJ_POWERCORE:
		case BaseObject::OBJ_STIMPACK:
		case BaseObject::OBJ_KEYCARD:
			CreatePickUp(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities);
				break;

		case BaseObject::OBJ_GUARD_SPAWNER:
		case BaseObject::OBJ_DOG_SPAWNER:
			CreateSpawner(tileid, homeNode, numEnemies, waypoints, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities);
			break;
		
		case BaseObject::OBJ_TRIP_LASER:
			break;
		case BaseObject::OBJ_COMPUTER:
			CreateComputer({ (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities, Event1.c_str(), Event2.c_str());
			break;
		case BaseObject::OBJ_ULCSHADOW:
		case BaseObject::OBJ_URCSHADOW:
		case BaseObject::OBJ_BRCSHADOW:
		case BaseObject::OBJ_FILLSHADOW:
		case BaseObject::OBJ_BLCSHADOW:
			CreateShadow(tileid, { (float)posX * tileWidth, (float)posY * tileHeight }, m_pEntities);
			break;
		};
	
		
		objectInfo = objectInfo->NextSiblingElement("object_info");
		



	}

	/*for (unsigned int currRect = 0; currRect < tStruct.pTiles.GetRectVec().size(); currRect++)
	{
		if (tStruct.layers.GetTiles()[currRect].GetTileID() == 16)
			FOVCollidables.push_back(new SGD::Rectangle(tStruct.pTiles.GetRectVec()[currRect]));


	}*/

	
	//Player* player = dynamic_cast<Player*>(m_pPlayer);

	if (currProfile.CheckPointReached == true)
	{
		player->SetPosition(m_ptCheckPtStart);
	}
	
	tileTexture = pGraphics->LoadTexture(tStruct.map.GetTilePath().c_str());


	return player;
}
void MapManager::UnloadLevel(void)
{

	for (unsigned int i = 0; i < tStruct.map.GetMapHeight(); i++)
	{
		delete[] tStruct.layers.m_vTiles[i];
	}
	delete [] tStruct.layers.m_vTiles;

}

void MapManager::Render()
{
	SGD::GraphicsManager * pGraphics = SGD::GraphicsManager::GetInstance();
	
	for (int currRow = startRow; currRow < endRow; currRow++)
	{
		for (int currCol = startCol; currCol < endCol; currCol++)
		{
			SGD::Point point = tStruct.layers.m_vTiles[currRow][currCol].worldPos;
			point.Offset({ -GameplayState::GetInstance()->GetCamera()->GetPosition().x, -GameplayState::GetInstance()->GetCamera()->GetPosition().y });

			pGraphics->DrawTextureSection(tileTexture,
			 point,
				SGD::Rectangle(tStruct.layers.m_vTiles[currRow][currCol].renderPos, tStruct.tileSize));
		}
	}
}

void MapManager::Update(float elapsedTime)
{
	SGD::Rectangle cameraRect = GameplayState::GetInstance()->GetCamera()->GetRect();

	startCol = (int)cameraRect.left / (int)tStruct.tileSize.width;
	startRow = (int)cameraRect.top / (int)tStruct.tileSize.height;
	endCol = ((int)Game::GetInstance()->GetScreenWidth() + cameraRect.left) / (int)tStruct.tileSize.width;
	endRow = ((int)Game::GetInstance()->GetScreenHeight() + cameraRect.top) / (int)tStruct.tileSize.height;
	endRow++;
	endCol++;
	if (startCol < 0)
	{
		startCol = 0;
	}

	if (startRow < 0)
	{
		startRow = 0;
	}
	if (endCol > tStruct.map.GetMapWidth())
	{
		endCol = tStruct.map.GetMapWidth();
	}

	if (endRow > tStruct.map.GetMapHeight())
	{
		endRow = tStruct.map.GetMapHeight();
	}
}

void MapManager::HandleCollision(const IBase* pOther)
{
	/*for (unsigned int i = 0; i < tStruct.pTiles.GetRectVec().size(); i++)
	{
		if (tStruct.pTiles.GetCollisionID() == 1)
		{

		}
	}*/
}

void MapManager::UnloadTexture(SGD::HTexture)
{
	SGD::GraphicsManager * pGraphics = SGD::GraphicsManager::GetInstance();

	pGraphics->UnloadTexture(GetMapTexture());
}


Player* MapManager::CreatePlayer(int type, SGD::Point pos, EntityManager* entities)
{
	Player* player = new Player;
	player->SetPosition(pos);
	player->SetRotation(0.0f);
	player->SetMoveSpeed(180.0f);
	player->RetrieveBehavior("playerController");


	// added
	player->SetAnimation("playerIdle");

	return player;
}


void MapManager::CreateSpawner(int type, int graphIndex, int numEnemies, std::vector<int>& waypoints, SGD::Point pos, EntityManager* entities)
{
	SpawnDoor* spawner = new SpawnDoor;
	spawner->SetPosition(pos);
	spawner->SetType(type);
	spawner->SetGraphIndex(graphIndex);
	spawner->SetMaxEnemyCount(numEnemies);
	spawner->GetWaypoints() = waypoints;
	entities->AddEntity(spawner, BUCKET_NONCOLLIDABLE);
	spawner->Release();
	spawner = nullptr;

	
	
}

void MapManager::CreateComputer(SGD::Point pos, EntityManager* entities, const char* _event1, const char* _event2)
{
	Computer* computer = new Computer;
	computer->SetPosition(pos);
	computer->SetRotation(0.0f);
	computer->SetTriggerEvent(_event1);
	computer->RegisterForEvent(_event1);
	computer->SetShutDownEvent(_event2);


	entities->AddEntity(computer, BUCKET_NONCOLLIDABLE);
	computer->Release();
	computer = nullptr;
}


void MapManager::CreateEnvironment(int type, SGD::Point pos, vector<SGD::Rectangle*>& FOVCollidables, EntityManager* entities, const char* event)
{
	EnvironmentalObject* object = new EnvironmentalObject;
	object->SetPosition(pos);
	if (event != nullptr)
	{
		if (type == BaseObject::OBJ_WALL && event == "PlayerOnly")
		{
			object->SetType(BaseObject::OBJ_PLAYERCOLLISION);
		}
		else
		{
			object->RegisterForEvent(event);
			object->SetEvent(event);
			object->SetType(type);
		}
		
	}
		
	
	object->SetSize({ 64, 64 });
	SGD::Rectangle* collider = new SGD::Rectangle(object->GetRect());

	FOVCollidables.push_back(collider);
	entities->AddEntity(object, BUCKET_ENVIRO);
	object->Release();
	object = nullptr;

}
void MapManager::CreateEnemy(int type, int homeNode, int alarmNode, int startState, SGD::Point pos, EntityManager* entities, Player* player, Graph<SGD::Point*>& _navGraph, std::vector<SGD::Rectangle*>& FOVCollidables, std::vector<int>& waypoints, const char* pEvent)
{
	switch (type)
	{
	case BaseObject::OBJ_WORKER:
	{
								   Worker* worker = new Worker;
								   worker->SetPosition(pos);
								   worker->SetRotation(0.0f);
								//   worker->SetTarget(dynamic_cast<Player*>(m_pPlayer));
								  

								   worker->RetrieveBehavior("move");
								   worker->SetMoveSpeed(100.0f);
								 //  worker->GetWaypoints() = waypoints;
								   worker->SetAIState(startState);
								   worker->SetHomeNode(homeNode);
								   worker->SetAlarmNode(alarmNode);
								   worker->SetTarget(player);
								   worker->GetWaypoints() = waypoints;
								   worker->SetNavGraph(&_navGraph);
								   worker->findFirstPath(waypoints[0], waypoints[1], worker->GetCurrPath());
								   worker->FOVSetUp(FOVCollidables);
								   entities->AddEntity(worker, BUCKET_ENEMIES);
								   worker->Release();
								   worker = nullptr;
	}

		break;
	case BaseObject::OBJ_GUARD:
	{
								  Guard* guard = new Guard;
								  guard->SetPosition(pos);
								  guard->SetRotation(0.0f);
								 
								  guard->RetrieveBehavior("runTo");
								  guard->SetMoveSpeed(100.0f);
								  guard->SetAIState(startState);

								  guard->SetHomeNode(homeNode);
								  guard->SetAlarmNode(alarmNode);
								  guard->SetTarget(player);
								  guard->GetWaypoints() = waypoints;
								  guard->SetNavGraph(&_navGraph);
								  guard->findFirstPath(waypoints[0], waypoints[1], guard->GetCurrPath());
								  guard->FOVSetUp(FOVCollidables);

								  entities->AddEntity(guard, BUCKET_ENEMIES);
								  guard->Release();
								  guard = nullptr;

								
	}
		break;


	case BaseObject::OBJ_OFFICER:
	{
									Officer* officer = new Officer;
									officer->SetPosition(pos);
									officer->SetRotation(0.0f);
								//	officer->SetTarget(dynamic_cast<Player*>(m_pPlayer));
									//	officer->SetSize({ 64, 64 });
									
									officer->SetAIState(startState);
									officer->FOVSetUp(FOVCollidables);

									officer->RetrieveBehavior("move");
									officer->SetMoveSpeed(100.0f);
									/*officer->GetWaypoints().push_back(SGD::Point(0, 0));
									officer->GetWaypoints().push_back(SGD::Point(900, 0));*/
									officer->SetHomeNode(homeNode);
									officer->SetAlarmNode(alarmNode);
									officer->SetTarget(player);
									officer->GetWaypoints() = waypoints;
									officer->SetNavGraph(&_navGraph);

									entities->AddEntity(officer, BUCKET_ENEMIES);
									officer->Release();
									officer = nullptr;
	}
		break;
	case BaseObject::OBJ_CAMERA:
	case BaseObject::OBJ_THERMAL_CAM:
	{
								   SecurityCamera* camera = new SecurityCamera;
								   camera->SetPosition(pos);
								   camera->SetRotation(0.0f);
							//	   camera->SetTarget(dynamic_cast<Player*>(m_pPlayer));
							   if (type == BaseObject::OBJ_THERMAL_CAM)
									   camera->SetThermal(true);
								   else
									   camera->SetThermal(false);
									  camera->SetAIState(startState);

								   camera->RetrieveBehavior("rotate");
								   camera->SetMoveSpeed(100.0f);
								   camera->GetWaypoints() = waypoints;
								   camera->SetNavGraph(&_navGraph);
								  
								   if (pEvent != "")
								   {
									   camera->SetShutDownEvent(pEvent);
									   camera->RegisterForEvent(pEvent);
								   }
								   
								   camera->FOVSetUp(FOVCollidables);

								   camera->SetTarget(player);

								   entities->AddEntity(camera, BUCKET_ENEMIES);
								   camera->Release();
								   camera = nullptr;
	}
		break;
	case BaseObject::OBJ_TURRET:
	{
								   Turret* turret = new Turret;
								   turret->SetPosition(pos);
								   turret->SetRotation(0.0f);
							//	   turret->SetTarget(dynamic_cast<Player*>(m_pPlayer));
								   turret->SetTarget(player);
								   turret->GetWaypoints() = waypoints;
								   turret->SetNavGraph(&_navGraph);
								   turret->RetrieveBehavior("rotate");
								   turret->SetMoveSpeed(100.0f);
							/*	   turret->GetWaypoints().push_back(SGD::Point(32, 288));
								   turret->GetWaypoints().push_back(SGD::Point(1440, 288));*/
								   turret->SetAIState(startState);
								   turret->FOVSetUp(FOVCollidables);

								   entities->AddEntity(turret, BUCKET_ENEMIES);
								   turret->Release();
								   turret = nullptr;
	}
		break;
	}
}


void MapManager::CreatePickUp(int type, SGD::Point pos, EntityManager* entities)
{
	PickUp* pickup = new PickUp;

	pickup->SetType(type);
	pickup->SetPosition(pos);

	switch (type)
	{
	case BaseObject::OBJ_KEYCARD:
		pickup->SetAnimation("keycard");
		break;
	case BaseObject::OBJ_POWERCORE:
		pickup->SetAnimation("powerCore");
		break;
	case BaseObject::OBJ_STIMPACK:
		pickup->SetAnimation("stimPack");
		break;
	case BaseObject::OBJ_INTEL:
		pickup->SetAnimation("stimPack");
		break;

	}
	entities->AddEntity(pickup, BUCKET_ENVIRO);
	pickup->Release();
	pickup = nullptr;
}

void MapManager::CreateKeyPad(int type, SGD::Point pos, EntityManager* entities, const char* _event1, const char* _event2)
{
	KeyPad* keypad = new KeyPad;

	keypad->SetDoorEvent(_event2);
	keypad->SetTriggerEvent(_event1);
	keypad->RegisterForEvent(_event1);
	
	keypad->SetPosition(pos);


	entities->AddEntity(keypad, BUCKET_NONCOLLIDABLE);
	keypad->Release();
	keypad = nullptr;
}
void MapManager::CreateDoor(int type, SGD::Point pos, EntityManager* entities, const char* event)
{
	Door* door = new Door;

	
	door->SetPosition(pos);
	door->SetDoorRect({pos.x, pos.y, pos.x, pos.y + 60});
	door->SetKeyPadEvent(event);
	door->RegisterForEvent(event);
	entities->AddEntity(door, BUCKET_ENVIRO);
	door->Release();
	door = nullptr;
}
void MapManager::CreateAlarmButton(int type, SGD::Point pos, EntityManager* entities, const char* event)
{
	PickUp* pickup = new PickUp;

	pickup->SetType(type);
	pickup->SetPosition(pos);


	
	entities->AddEntity(pickup, BUCKET_NONCOLLIDABLE);
	pickup->Release();
	pickup = nullptr;
}

void  MapManager::LoadLevelPaths(void)
{
	ifstream fin("resource/config/levels/levelPaths.txt", std::ios::out);

	if (fin.is_open())
	{
		unsigned int count = 0;
		for (unsigned int count = 0; !fin.eof() ; count++)
		{
			getline(fin, levels[count]);
		}
	}
}
void MapManager::CreateShadow(int type, SGD::Point pos, EntityManager* entities)
{
	Shadow * temp = new Shadow;
	temp->SetType(type);
	temp->SetPosition(pos);
	temp->SetSize({ 64, 64 });
	switch (type)
	{
	case BaseObject::OBJ_ULCSHADOW:
		temp->SetRenderRect({ 0.0f, 0.0f, 64.0f, 64.0f });
		break;
	case BaseObject::OBJ_URCSHADOW:
		temp->SetRenderRect({ 0.0f, 64.0f, 64.0f, 128.0f });
		break;
	case BaseObject::OBJ_BLCSHADOW:
		temp->SetRenderRect({ 0.0f, 0.0f, 64.0f, 64.0f });
		break;
	case BaseObject::OBJ_BRCSHADOW:
		temp->SetRenderRect({ 128.0f, 64.0f, 192.0f, 128.0f });
		break;
	case BaseObject::OBJ_FILLSHADOW:
		temp->SetRenderRect({ 64.0f, 0.0f, 128.0f, 64.0f });
		break;
	}
	entities->AddEntity(temp, BUCKET_SHADOWS);
	temp->Release();
	temp = nullptr;
}
